﻿#region Copyright Info

// 
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System.Windows;
using System.Windows.Controls;
using Majesty_of_Omega.GUI.Utility;

#endregion

namespace Majesty_of_Omega.GUI.Controls
{
    /// <summary>
    /// This class enables displaying simple formatted text strings.
    /// </summary>
    public class MooTextBlock : TextBlock
    {
        /// <summary>
        /// Gets or sets the rich text string
        /// </summary>
        /// <value>The rich text.</value>
        public string RichText
        {
            get { return (string) GetValue(RichTextProperty); }
            set { SetValue(RichTextProperty, value); }
        }

        /// <summary>
        /// The RichText DependendyProperty
        /// </summary>
        public static readonly DependencyProperty RichTextProperty =
            DependencyProperty.Register("RichText", typeof (string), typeof (MooTextBlock),
                                        new UIPropertyMetadata(null, OnRichTextChanged));


        /// <summary>
        /// Called when the RichText value changed.
        /// </summary>
        /// <param name="d">The d.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void OnRichTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MooTextToInlineConverter converter = new MooTextToInlineConverter();
            MooTextBlock mooTextBlock = (MooTextBlock) d;
            mooTextBlock.Inlines.Clear();
            mooTextBlock.Inlines.AddRange(converter.ConvertMooTextToInlines((string) e.NewValue));
        }
    }
}